﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using System.Web.Security;
using JinJun.YShowReception.BLL.IService;
using JinJun.YShowReception.Model;
using JinJun.YShowReception.Web.Attributes;
using JinJun.YShowReception.Web.Models;

namespace JinJun.YShowReception.Web.Controllers
{
    public class HomeController : Controller
    {
        private IUserInfoService _userInfoService;
        public HomeController(IUserInfoService userInfoService)
        {
            _userInfoService = userInfoService;
        }


        //主页
        [PermissionAttribute]
        public ActionResult Index()
        {
            return View();
        }

        //登录页面
        public ActionResult Login()
        {
            //取cookie里面的信息
            var cookie = System.Web.HttpContext.Current.Request.Cookies[FormsAuthentication.FormsCookieName];
            if (cookie != null)
            {
                //获取存在的cookie
                var ticket = FormsAuthentication.Decrypt(cookie.Value);
                string userData = ticket.UserData;
                if (!string.IsNullOrEmpty(userData))
                {
                    //存储在session里面
                    UserInfo userInfo = new UserInfo();
                    userInfo.Id = Convert.ToInt32(userData.Split('#')[0]);
                    userInfo.UserName = userData.Split('#')[1];
                    userInfo.Pwd = userData.Split('#')[2];
                    UserInfoContext.userInfoContext.UserInfo = userInfo;
                    return Redirect("/Home/Index");
                }
            }
            return View();
        }

        //注册页面      
        public ActionResult Register()
        {
            return View();
        }


        //商品详情页面
        public ActionResult Product_Detail()
        {
            return View();
        }

       
        public ActionResult About()
        {
            ViewBag.Message = "Your application description page.";

            return View();
        }

        public ActionResult Contact()
        {
            ViewBag.Message = "Your contact page.";

            return View();
        }
    }
}